package cn.com.w.log.demo.slf4j.fluent;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Temperature {

    static Logger logger = LoggerFactory.getLogger(Temperature.class);

    public static void main(String[] args) {
        int newT = 15;
        int oldT = 16;
        // 使用传统 API
        logger.info("Temperature set to {}. Old temperature was {}.", newT, oldT);

        // 使用fluent API，逐个添加参数，然后记录消息
        logger.atInfo().addArgument(newT).addArgument(oldT).log("Temperature set to {}. Old temperature was {}.");

        // 使用fluent API，记录带有参数的消息
        logger.atInfo().log("Temperature set to {}. Old temperature was {}.", newT, oldT);

        // 使用fluent API，添加一个参数，然后记录消息，提供更多的参数
        logger.atInfo().addArgument(newT).log("Temperature set to {}. Old temperature was {}.", oldT);

        // 使用fluent API, 通过函数式接口Supplier提供一个参数， 然后记录消息，提供更多的参数
        logger.atInfo().addArgument(() -> getNumber()).log("Temperature set to {}. Old temperature was {}.", oldT);
    }

    public static double getNumber(){
        return Math.random()*4;
    }
}
